n, m = map(int, input().split())
for _ in range(m):
    line = list(map(int, input().split()))
    op = line[0]
    if op == 1:
        x = line[1]
        print((n >> x) & 1)
    elif op == 2:
        l = line[1]
        r = line[2]
        sub = n & (pow(2, l) - 1)
        x = n >> l
        x = ((x ^ (pow(2, (r - l + 1)) - 1)) << l) + sub
        print(x)
        n = x
    elif op == 3:
        l = line[1]
        r = line[2]
        sub = n & (pow(2, l) - 1)
        x = n >> l
        x = ((x | (pow(2, (r - l + 1)) - 1)) << l) + sub
        print(x)
        n = x
    elif op == 4:
        l = line[1]
        r = line[2]
        sub = n & (pow(2, l) - 1)
        x = n >> (r + 1)
        x = (x << (r + 1)) + sub
        print(x)
        n = x
    else:
        print(n & -n)
